import java.util.ArrayList;
import java.util.List;

/**
 * @author : cww
 * @date : 2021/1/23 16:15
 */
public class LightControl {
    private Command onCommand;
    private Command offCommand;
    private List<Command> commandList;
    public LightControl(Command on,Command off){
        onCommand = on;
        offCommand = off;
        commandList = new ArrayList<>();
    }
    public void on(){
        onCommand.execute();
        commandList.add(onCommand);
    }
    public void off(){
        offCommand.execute();
        commandList.add(offCommand);
    }
    public void undo(){
        if(commandList.size()==0){
            return;
        }
        commandList.get(commandList.size()-1).undo();
        commandList.remove(commandList.size()-1);
    }
}
